package pers.sloera.leetcode.editor.cn;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的日程安排表 I
 *
 * @author sloera
 * @date 2022-07-05 22:14:58
 */
class MyCalendarI {
    public static void main(String[] args) {
        MyCalendar myCalendar = new MyCalendarI().new MyCalendar();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class MyCalendar {
        List<int[]> schedules;

        public MyCalendar() {
            schedules = new ArrayList<>();
        }

        public boolean book(int start, int end) {
            // 统计所有符合条件的
            long validNum = schedules.stream().filter(schedule -> (end <= schedule[0] || start >= schedule[1])).count();
            if (validNum != schedules.size()) {
                // System.out.println(schedules);
                // System.out.println(schedules.stream().map(schedule -> "[" + schedule[0] + "," + schedule[1] + "]").collect(Collectors.joining(",")));
                return false;
            }
            schedules.add(new int[]{start, end});
            return true;
        }
    }

    /**
     * Your MyCalendar object will be instantiated and called as such:
     * MyCalendar obj = new MyCalendar();
     * boolean param_1 = obj.book(start,end);
     */
    //leetcode submit region end(Prohibit modification and deletion)

}
